﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using AssetAllocationSystem.Models;
using AssetAllocationSystem.Repositories;
using FluentNHibernate.MappingModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NHibernate;
using NHibernate.Collection.Generic;

namespace AssetAllocationSystem.Tests.RepositoriesFixtures
{
    /// <summary>
    /// Summary description for EmployeeRepositoryFixture
    /// </summary>
    [TestClass]
    public class EmployeeRepositoryFixture : FixtureBase
    {
        private static ISession session;
        public EmployeeRepositoryFixture()
        {
            //
            // TODO: Add constructor logic here
            //
            
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext)
        {
            session = CreateSession();

            for (int i = 1; i <= 5; i++)
            {
                var employee = new Employee();
                employee.Id = Guid.NewGuid();
                employee.Location = new Location();
                employee.Location.Code = "Location1";
                employee.Location.Id = Guid.Parse("41F69465-94F8-4895-A102-69C0D8A9F17A");
                employee.Name = "Employee1" + i;
                employee.Requests = null;
                employee.Allocations = null;
                employee.Company = null;
                
                session.Save(employee);
            }

            session.Flush();
        }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        [ClassCleanup()]
        public static void MyClassCleanup()
        {
            var repositoryBase = new RepositoryBase<Employee>(session);
            var employees = repositoryBase.FindAll();

            foreach (var employee in employees)
            {
                session.Delete(employee);
            }

            session.Flush();
        }
        //
        // Use TestInitialize to run code before running each test 
        [TestInitialize()]
        public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        [TestCleanup()]
        public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void Check_if_FindByLocationCode_works_well()
        {
            var employeeRepository = new EmployeeRepository(session);
            var companies = employeeRepository.FindByLocationCode("LOC1");

            Assert.IsNotNull(companies);
        }

        [TestMethod, Ignore]
        public void check_if_FindByPrimaryLocation_works_well()
        {
            var employeeRepository = new EmployeeRepository(session);
            var companies = employeeRepository.FindByPrimaryLocation("PrimaryLocation1");

            Assert.IsNotNull(companies);
        }

        [TestMethod, Ignore]
        public void check_if_FindByExistingLocation_works_well()
        {
            var employeeRepository = new EmployeeRepository(session);
            var companies = employeeRepository.FindByExistingLocation("ExistingLocation1");

            Assert.IsNotNull(companies);
        }
    }
}
